﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ServicesPayments
{
    public  class UIFactory
    {
        #region --SINGLETON--
        private static UIFactory _instance;

        public static UIFactory Instance
        {
            get { return _instance ?? (_instance = new UIFactory()); }
        }
        #endregion

        private Hashtable _formsCollection= new Hashtable();

        public frmCatalogueTemplate CreateCatalogueForm<T>() where T:CatalogEntryBase
        {
            frmCatalogueTemplate _frmToReturn;
            if (_formsCollection.ContainsKey(typeof(T)))
                _frmToReturn = (frmCatalogueTemplate)_formsCollection[typeof(T)];
            else
            {
                _frmToReturn = new frmCatalogueTemplate(typeof (T));
                _formsCollection.Add(typeof(T),_frmToReturn);
            }

            return _frmToReturn;
        }

        public void DisposeCollection()
        {
            foreach (DictionaryEntry entry in _formsCollection)
            {
                ((Form)entry.Value).Dispose();
            }
        }
    }
}
